mui.init(); //初始化 
//window.location.reload(); //页面实现刷新(和跳转)
//获取本地信息
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var preDeposit;
var mask = mui.createMask(); //遮罩层
window.onload = function() {
	mui.plusReady(function() {
		self = plus.webview.currentWebview();
		plus.nativeUI.closeWaiting(); //关闭等待
	});
}
$(function() {
	mui.ajax(integral_url + '/integral/getInfo', { //查询指定积分账户信息接口
		data: {
			"phone": my_phone,
			"sign": "string",
			"user_id": user_id
		},
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		headers: {
			'Content-Type': 'application/json'
		},
		success: function(data) {
			if(data.code == 10000) {
				var availableIntegr = data.resp.availableIntegr;
				$('#availableIntegr_num').text(availableIntegr); //可用积分
				var stockIntegr = data.resp.stockIntegr;
				$('#stockIntegr_num').text(stockIntegr); //存量积分 
				preDeposit = data.resp.preDeposit;
				$('#preDeposit_num').text(preDeposit); //预付款
				var repertoryIntegr = data.resp.repertoryIntegr;
				$('#repertoryIntegr_num').text(repertoryIntegr); //库存积分
				var digitalIntegr = data.resp.digitalIntegr;
				$('#digitalIntegr_num').text(digitalIntegr); //数字积分
				var tmIntegr = data.resp.tmIntegr;
				$('#tmIntegr_num').text(tmIntegr); //天美积分
				var universalIntegr = data.resp.universalIntegr;
				$('#universalIntegr_num').text(universalIntegr); //通兑积分
				var vrIntegr = data.resp.vrIntegr;
				$('#vrIntegr_num').text(vrIntegr); //VR积分
			} else {
				mui.alert(data.msg);
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；
			console.log(type);
			var error_msg = JSON.parse(xhr.responseText)
			mui.alert(error_msg.msg)
		}
	});
});
//预付款
document.getElementById("advance_payment").addEventListener("tap", function() {
	mui.openWindow({
		url: "advance.html",
		extras: {
			preDeposit: preDeposit
		},
		createNew: true
	});
});
//可用积分
document.getElementById("integral_detail").addEventListener("tap", function() {
	mui.openWindow({
		url: "integral_detail.html",
		createNew: true
	});
});
//存量积分
document.getElementById("stock_integral_detail").addEventListener("tap", function() {
	mui.openWindow({
		url: "stock_integral_detail.html",
		createNew: true
	});
});
//库存积分
document.getElementById("inventory_integral_detail").addEventListener("tap", function() {
	mui.openWindow({
		url: "inventory_integral_detail.html",
		createNew: true
	});
});

//数字积分
document.getElementById("reward_number_integral").addEventListener("tap", function() {
//	mui.toast('正在维护中')
		mui.openWindow({
			url: "shuzi_integral.html",
			createNew: true
		});
});

//天美积分
document.getElementById("reward_tinme_integral").addEventListener("tap", function() {
//	mui.toast('正在维护中')
		plus.nativeUI.showWaiting("加载中...");
		mask.show(); //显示遮罩层
		mui.ajax(user_url+'/api/findUserByPhoneIsTMX', { //查询是否有注册天美账号
			data: {
				"phone": my_phone,
				"sign": "string",
				"user_id": user_id
			},
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout: 10000, //超时时间设置为10秒；
			headers: {
				'Content-Type': 'application/json'
			},
			success: function(data) {
				//alert(JSON.stringify(data));
				if(data.code == 10000) {   
					plus.nativeUI.closeWaiting(); //关闭等待
				    mask.close(); //关闭遮罩层
					mui.openWindow({//天美积分兑换
						url: "tianmei_integral.html",
						createNew: true
					});
				} else {
					mui.alert(data.msg);
				}
			},
			error: function(xhr, type, errorThrown) { //异常处理；
				console.log(type);
				var error_msg = JSON.parse(xhr.responseText)
				mui.alert(error_msg.msg)
				plus.nativeUI.closeWaiting(); //关闭等待
				mask.close(); //关闭遮罩层
			}
		});  
});

//通兑积分
document.getElementById("reward_exchange_integral").addEventListener("tap", function() {
//	mui.toast('正在维护中')
		mui.openWindow({
			url: "reward_exchange_integral_detail.html",
			createNew: true
		});
});
//VR积分
document.getElementById("reward_vr_integral").addEventListener("tap", function() {
//	mui.toast('正在维护中')
		mui.openWindow({
			url: "reward_vr_integral_detail.html",
			createNew: true
		});
});
//返回user页面
document.getElementById("my_user_back").addEventListener("tap", function() {
	mui.openWindow({
		url: "../my/my_user.html",
		createNew: true
	});
});